package com.school.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.school.admin.common.result.R;
import com.school.admin.common.utils.UserInfoUtil;
import com.school.admin.entity.MallSysRole;
import com.school.admin.entity.queryVo.MallSysRoleQueryVo;
import com.school.admin.service.MallSysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author sunpx
 * @since 2022-03-24
 */
@RestController
@RequestMapping("/mall-sys-role")
@Api(tags = "角色相关")
public class MallSysRoleController {

    @Autowired
    MallSysRoleService mallSysRoleService;

    /**
     * 查询所有角色列表
     *
     * @return R
     * @author : sunpx
     * @date : 2022-03-25 21:19:06
     */
    @GetMapping("getOrgList")
    @ApiOperation("查询角色列表")
    public R getOrgList() {
        return R.ok().data("list", mallSysRoleService.list());
    }

    /**
     * @return : top.zzzit.main.matter.common.result.R
     * @author : zzz
     * @desc : TODO 查询角色列表
     * @date :  17:21:54
     * @params :
     */
    @PostMapping("queryPage")
    @ApiOperation("查询角色列表(分页)")
    public R queryPage(@RequestBody MallSysRoleQueryVo mallSysRoleQueryVo) {
        Page page = mallSysRoleService.page(mallSysRoleQueryVo.getPage());
        return R.ok().data("list", page);
    }

    @PostMapping("save")
    @ApiOperation("保存角色")
    public R saveRole(@RequestBody MallSysRole mallSysRole) {
        mallSysRole.setCreateId(UserInfoUtil.getUserId());
        mallSysRole.setCreateTime(new Date());
        mallSysRoleService.saveOrUpdate(mallSysRole);
        return R.ok();
    }

    @DeleteMapping("del/{id}")
    @ApiOperation("删除角色")
    public R delRole(@PathVariable String id) {
        mallSysRoleService.deleteRole(id);
        return R.ok();
    }


}

